// 请求拦截器
import {whiteList} from "../index.ts";
import {useRouter} from "vue-router";

const router = useRouter();


export const interceptorsRequestConfig = async (config: any) => {
    //判断是否有token，有就添加请求头
    const token = localStorage.getItem("token");
    if (token) {
        config.headers.common['token'] = token;
    } else if (whiteList.includes(config.url)) {
        return config;
    } else {
        await router.push('/login')
    }
}
export const interceptorsRequestConfigError = (error: any) => {

    return Promise.reject(error)
}


export const interceptorsResponseConfig = (response: any) => {
    return response;
}

export const interceptorsResponseConfigError = (error: any) => {
    return Promise.reject(error)
}

